﻿using Tszy.Unlimited.Base.Extensions;

namespace Tszy.CodeBuilder.Models;

/// <summary>
/// 配置数据。
/// </summary>
public class SettingData
{
    /// <summary>
    /// 配置实例。
    /// </summary>
    public static SettingData Instance { get; private set; } = new SettingData();

    /// <summary>
    /// 是否调试。
    /// </summary>
    public bool IsDebug { get; set; }

    /// <summary>
    /// 数据库连接配置。
    /// </summary>
    public DatabaseConfig Database { get; set; } = new DatabaseConfig();

    /// <summary>
    /// 设置配置信息。
    /// </summary>
    /// <param name="settings">配置信息。</param>
    public static void Initialize(SettingData settings)
    {
        Instance = settings ?? throw new ArgumentNullException(nameof(settings));
    }
}

/// <summary>
/// 数据库连接配置。
/// </summary>
public class DatabaseConfig
{
    private string _connection = string.Empty;

    /// <summary>
    /// 数据库连接。
    /// </summary>
    public string DbConnection
    {
        get
        {
            if (!string.IsNullOrWhiteSpace(DbKey))
            {
                return _connection.AES32Decrypt(DbKey);
            }

            return _connection ?? string.Empty;
        }
        set
        {
            _connection = value;
        }
    }

    /// <summary>
    /// 数据库连接加密 KEY。
    /// </summary>
    public string DbKey { get; set; } = string.Empty;
}